package com.itheima.demo1creat;

public class ThreadDemo4
{
    public static void main(String[] args) {
        //取名
        Thread t1 = new MyThread2();
        //取名要在启动前
        t1.setName("线程1");
        t1.start();
        System.out.println(t1.getName());
        Thread t2 = new MyThread2();
        t2.setName("线程2");
        t2.start();
        System.out.println(t2.getName());
        Thread m=Thread.currentThread();
        System.out.println(m.getName());
    }
}

class MyThread2 extends Thread
{
    //设置有参构造器 填名字
    public MyThread2(String name)
    {
        super(name);
    }
    public MyThread2() {}
    //重写run方法
    @Override
    public void run()
    {
        for (int i = 0; i < 5; i++)
        {
            System.out.println(Thread.currentThread().getName()+"子线程输出"+i);
        }
    }
}

